package com.netty4.handler.codec.msgpack;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageDecoder;
import org.msgpack.MessagePack;

import java.util.List;

public class MsgPackDecoder extends MessageToMessageDecoder<ByteBuf> {
    protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf buf, List<Object> list) throws Exception {
        final  byte [] bytes;
        final int length = buf.readableBytes();
        bytes = new byte[length];
        buf.getBytes(buf.readerIndex(),bytes,0,length);
        MessagePack messagePack = new MessagePack();
        list.add(messagePack.read(bytes));
    }
}
